home *** CD-ROM | disk | FTP | other *** search
/ Freelog 46 / Freelog046.iso / Alu / Celestia / Win32LoresTex / celestia-lores-win32-1.3.0.exe / {app} / shaders / bumphaze.vp < prev    next >
Text File  |  2003-03-05  |  2KB  |  66 lines

  1. !!VP1.0
  2.  
  3. # Compute the surface space light vectors for diffuse bump mapping as well
  4. # as a fog factor for an atmospheric haze effect.
  5.  
  6. # c[0]..c[3] contains the concatenation of the modelview and projection matrices.
  7. # c[4]..c[7] contains the inverse transpose of the modelview
  8. # c[15] contains the eye position in object space
  9. # c[16] contains the light direction in object space
  10. # c[17] contains H, the normalized sum of the eye and light direction
  11. # c[20] contains the light color * object color
  12. # c[32] contains the ambient light color * object color
  13. # c[33] contains the haze color
  14. # c[40] contains (0, 1, 0.5, specPower)
  15. # v[6] contains the tangent vector
  16.  
  17. # Transform the vertex by the modelview matrix
  18. DP4   o[HPOS].x, c[0], v[OPOS];
  19. DP4   o[HPOS].y, c[1], v[OPOS];
  20. DP4   o[HPOS].z, c[2], v[OPOS];
  21. DP4   o[HPOS].w, c[3], v[OPOS];
  22.  
  23. # Compute the diffuse light component and clamp it to zero
  24. DP3   R2, v[NRML], c[16];
  25. MAX   R2.x, R2, c[40].xxxx;
  26.  
  27. # Get the normalized vector from the eye to the vertex
  28. ADD   R4, c[15], -v[OPOS];
  29. DP3   R0.w, R4, R4;
  30. RSQ   R0.w, R0.w;
  31. MUL   R4.xyz, R4, R0.w;
  32.  
  33. # Output the fog factor
  34. DP3   R2.y, v[NRML], R4;
  35. ADD   R2.y, c[40].y, -R2.y;
  36. MUL   o[FOGC].x, R2.x, R2.y;
  37.  
  38. # We're done with the haze/fog stuff; now compute the surface space
  39. # light direction.
  40. MOV   R1, v[NRML];
  41. MOV   R2, v[6];
  42.  
  43. # Compute the binormal--cross product of normal and tangent
  44. MUL   R3, R1.zxyw, R2.yzxw;
  45. MAD   R3, R1.yzxw, R2.zxyw, -R3;
  46.  
  47. # Assume that the tangent and normal are orthonormal; otherwise
  48. # we need to normalize R3
  49. #DP3   R0.w, R3, R3;
  50. #RSQ   R0.w, R0.w;
  51. #MUL   R3.xyz, R3, R0.w;
  52.  
  53. # Transform the light direction from object space into surface space
  54. DP3   R0.x, R2, c[16];
  55. DP3   R0.y, R3, c[16];
  56. DP3   R0.z, R1, c[16];
  57. # Compress the light direction to fit in the primary color and output it
  58. MOV   R5, c[40];
  59. MAD   o[COL0], R0, R5.z, R5.z;
  60.  
  61. # Output the texture coordinates.
  62. MOV   o[TEX0], v[TEX0];
  63. MOV   o[TEX1], v[TEX1];
  64.  
  65. END
  66.